package com.link.base.tencent.thirdclient.wechat.controller;

import com.link.base.tencent.thirdclient.wechat.service.WxLoginService;
import com.link.core.cllog.LCLogger;
import com.link.base.tencent.thirdclient.wechat.model.WxLogin;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;
import org.springframework.web.bind.annotation.RestController;

import javax.annotation.Resource;
import java.util.HashMap;
import java.util.Map;

/**
 * 微信登录控制器
 *
 * @author LiQun
 * @date 2018/2/26 10:14
 */
@RestController
@RequestMapping("/weixin/login")
public class WxLoginController {

    @Resource
    private WxLoginService wxLoginService;

    /**
     * 微信登录
     *
     * @author LiQun
     * @date 2018/2/26 10:14
     * @param wxLogin 传递参数对象
     */
    @RequestMapping(value = "/getWeChatInfo")
    @ResponseBody
    public Map<String, Object> getWeChatInfo(@RequestBody WxLogin wxLogin) {
        Map<String, Object> result = new HashMap<String, Object>();

        try {
            wxLogin = wxLoginService.getWeChatInfo(wxLogin);
            result.put("result", wxLogin);
            result.put("success", true);
        } catch (Exception e) {
            LCLogger.withException(e);
            result.put("success", false);
            result.put("message", e.getMessage());
        }
        return result;
    }
}
